<!doctype html>
<html lang="en">

	<head>
		<meta charset="UTF-8" />
		<title>Document</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="css/mui.min.css" />
		<style>
			.whole {
				padding:0 15px;
				text-align: center;
			}
			
			#head {
				display: inline-block;
				width: 100px;
				height: 100px;
				position: relative;
				top: 18px;
				cursor: pointer;
				text-align: center;

			}
			
			#ps {
				border-radius: 50px;
				width: 100%;
				height: 100%;
				border: 1px solid darkgray;
				margin-bottom: 20px;
				
			}
			
			#file_img {
				display: none;
			}
			#sub{
				width:100%;
				margin:50px 0;
			}
		</style>
	</head>

	<body>

		<header class="mui-bar mui-bar-nav">
			<a href="javascript:history.go(-1)" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">修改头像</h1>
		</header>

		<div class="mui-content whole">
				<form action="#" method="post" enctype="multipart/form-data">
					<div id="head">
						<img src="img/logo1.png" id="ps" />
						<input type="file" id="file_img" accept="image/*" />
						<button type="button" id="change_file" class="mui-btn">选择图片</button>
					
					</div>
					<button type="button" id="sub" class="mui-btn mui-btn-blue">上传</button>
				</form>
		</div>

		<script src="js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			mui.init()
			
			$('#change_file').click(()=>{
				$('#file_img').click()
			})
			
			$('#file_img').change(function(){
				let img = this.files[0]
				let reader = new FileReader()
				reader.readAsDataURL(img)
				reader.onload=e=>{
					$('#ps').attr('src',e.target.result)
					$('#change_file').html('重新选择')
				}
			})
			$('#sub').click(()=>{
				if(!$('#file_img')[0].files[0]){
					mui.toast('请选择图片')
					return false
				}
				$('form').submit()
			})

		</script>
	</body>

</html>